<?php
namespace addons\TfFutures\backend\controllers;

use Yii;
use common\components\Curd;
use addons\TfFutures\common\models\Setup;
/**
 * 文章管理
 *
 * Class ArticleController
 * @package addons\TfFutures\backend\controllers
 * @author jianyan74 <751393839@qq.com>
 */
class SetupController extends BaseController
{
    use Curd;

    /**
     * @var Setup
     */
    public $modelClass = Setup::class;

    /**
     * 首页
     *
     * @return mixed
     */
    public function actionIndex()
    {
        $models = $this->modelClass::findOne(1);

        return $this->render($this->action->id, [
            'models' => $models,
        ]);
    }
    /**
     * 编辑/创建
     *
     * @return string|\yii\console\Response|\yii\web\Response
     * @throws \yii\db\Exception
     */
    public function actionEdit($id)
    {
        $request = Yii::$app->request->post();
        $model = $this->modelClass::findOne(1);
        if(empty($model)){
            $this->message("获取数据失败", $this->redirect(['index']), 'error');
        }
        $model->updated_at = time();
        if ($model->load($request)&& $model->save()) {
           $this->message("修改成功", $this->redirect(['index']), 'success');
        }

        return $this->renderAjax($this->action->id, [
            'model' => $model,
        ]);

    }

}